<?php defined('SYSPATH') or die('No direct script access.');

abstract class Controller_Admin_Base extends Controller
{
	// Модели
	protected $main_model = null;
	protected $user_model = null;
    protected $article_model  = null;
    protected $category_model = null;
    protected $page_model = null;
    protected $setting_model = null;
    protected $banner_model = null;
    protected $article_comment_model = null;
    protected $company_model = null;
    protected $gallery_model = null;
	
	// Темплейты
	protected $main_tpl = 'admin/main_tpl';
	
	// Настройки
	protected $need_auth = true;	// Нужна авторизация
	
	// Юзер
	protected $user = null;
    
    // Настройки
    protected $settings = null;
    
    // Баннеры
    protected $banners = null;

	public function before()
	{
		parent::before();
        
        // Настройки
        //Upload::$default_directory = 'media/uploads/';
		
		// Проверка авторизации
		if($this->need_auth && !Auth::instance()->logged_in())
		{
			Request::current()->redirect('admin/login');
		}
		
		// Юзер
		$this->user = Auth::instance()->get_user();
		
		// Модели
		$this->main_model = new Model_Main;
		$this->user_model = new Model_Users;
        $this->article_model  = new Model_Articles;
        $this->category_model = new Model_Categories;
        $this->page_model = new Model_Pages;
        $this->setting_model = new Model_Settings;
        $this->banner_model = new Model_Banners;
        $this->article_comment_model = new Model_ArticleComments;
        $this->company_model = new Model_Companies;
        $this->gallery_model = new Model_Gallery;
        
        // Настройки
        $this->settings = $this->setting_model->process_settings($this->setting_model->get_settings());
        
        // Баннеры
        $this->banners = $this->banner_model->process_banners($this->banner_model->get_banners());
		
		// Темплейты
		$this->main_tpl = new View($this->main_tpl);
	}
	
	public function print_template($title, $content, $menu)
	{
		$this->main_tpl->title   = $title;
		$this->main_tpl->content = $content;
        $this->main_tpl->menu    = $menu;
        $this->main_tpl->user    = $this->user;
		
		$this->response->body($this->main_tpl);
	}

} // End Base
